<div class="row">
  <div class="col-lg-12">
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>设置当前活动</h5>
      </div>
      <div class="ibox-content">
        <%= form_for set_current_event_path, html: {class: 'form-horizontal'} do |f|%>
          <div class="form-group"><label class="col-sm-2 control-label">活码链接</label>
            <div class="col-sm-3">
              <label id="qrcode-link"></label>
            </div>
          </div>

          <div class="form-group"><label class="col-sm-2 control-label">二维码</label>
            <div class="col-sm-3">
              <div id="qrcode"></div>
            </div>
          </div>

          <div class="form-group"><label class="col-sm-2 control-label">当前活动</label>
            <div class="col-sm-3">
              <label>
                <% if @current_active_event.present? %>
                  <%= @current_active_event.name %>
                <% else %>
                  <%= "无" %>
                <% end %>
              </label>
            </div>
          </div>

          <div class="form-group"><label class="col-sm-2 control-label">请选择活动</label>
            <div class="col-sm-3"> 
              <%=select_tag :event_id, options_for_select(@events.map {|s| [s.name, s.id]}), include_blank: false, class: 'input-sm form-control input-s-sm inline'%>
            </div>
          </div>

          <div class="form-group">
            <div class="col-sm-4 col-sm-offset-2">
              <%= button_tag '保存', class: 'btn btn-primary'%>
            </div>
          </div>

        <% end %>
      </div>
    </div>
  </div>
</div>
<%= javascript_include_tag 'http://www.luqidong.com/demo/qrcode/js/qrcode.js' %>
<script type="text/javascript">
  //生成二维码
  $(function(){
    var qrcode = new QRCode($("#qrcode")[0], {
      width : 120,//设置宽高
      height : 120
    });
    var qrcode_value = "http://"+window.location.host+"/get_current_event";
    qrcode.makeCode(qrcode_value);
    $('#qrcode-link').text(qrcode_value);
  });
</script>